//
//  DFProductGroupCell.swift
//  DailyFresh
//
//  Created by Arthur on 2017/9/26.
//  Copyright © 2017年 DailyFresh. All rights reserved.
//

import UIKit

let DFGroupImageCellHeight = normalize(value: 140)
let DFGroupTextCellHeight = normalize(value: 70)

// 文字
class DFProductGroupTextCell: UICollectionViewCell {
    override init(frame: CGRect) {
        super.init(frame: frame)
        self._setupUI()
        
    }
    
    private func _setupUI() {
        self.backgroundColor = UIColor.white
        self.addSubview(title)
        self.addSubview(subTitle)
        
        title.snp.makeConstraints { (make) in
            make.left.equalTo(DFLayoutConstants.margin)
            make.top.equalTo(normalize(value: 30))
            make.width.equalTo(self)
            make.height.equalTo(25)
        }
        
        subTitle.snp.makeConstraints { (make) in
            make.left.equalTo(DFLayoutConstants.margin)
            make.top.equalTo(title.snp.bottom).offset(normalize(value: 5))
            make.width.equalTo(self)
            make.height.equalTo(12)
        }
    }
    
    func update(group: DFProductGroupModel) -> Void {
        self.title.text = group.name
        self.subTitle.text = group.second_title
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var title: UILabel = {
        let tmp = UILabel()
        tmp.text = ""
        tmp.textColor = DFColorConstants.black
        tmp.font = UIFont.boldSystemFont(ofSize: 20)
        return tmp
    }()
    
    lazy var subTitle: UILabel = {
        let tmp = UILabel()
        tmp.text = ""
        tmp.textColor = DFColorConstants.gray
        tmp.font = UIFont.systemFont(ofSize: 12)
        return tmp
    }()
}

// 图片
class DFProductGroupImageCell: UICollectionViewCell {
    var imagesUrlStringArray:Array<String> = []
//    weak var delegate:DFBannerCellDelegate?
    lazy var bannerView:DFBannerView = {
        [unowned self] in
        let temp = DFBannerView()
//        temp.delegate = self
        return temp
        }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.addSubview(self.bannerView)
        bannerView.snp.makeConstraints { (make) in
            make.edges.equalTo(self).inset(UIEdgeInsetsMake(normalize(value: 30), 0, 0, 0))
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK:- 刷新banner
    func update(group: DFProductGroupModel) -> Void {
        let bannerItems = group.bannerArray
        if bannerItems.count != 0 {
            imagesUrlStringArray = []
            for item in bannerItems {
                imagesUrlStringArray.append(item.path)
            }
            self.bannerView.update(imageURLStringGroup: imagesUrlStringArray)
        }
    }
}

